import config from "@/config/config.js";
import http from "@/api/http.js";


const TestProcessRequest = {
    loadProcess(TestProcess,page=1,limit=10,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.defectBaseUrl + "/process/list?page="+page + "&limit="+limit;
            if(TestProcess){
                if (TestProcess.processId){
                    url += "&processId=" + TestProcess.processId;
                }
                if(TestProcess.materialName){
                    url += "&materialName=" + TestProcess.materialName;
                }
                if (TestProcess.processType){
                    url += "&processType=" + TestProcess.processType;
                }
            }
            http.get(url,callBack);
        }else {
            callBack(undefined);
        }
    },
    saveProcess(TestProcess,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/process/save";
            http.post(url,TestProcess,callBack);
        }else {
            callBack(undefined);
        }
    },
    updateProcessById(TestProcess,callBack) {
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/process/update";
            http.put(url,TestProcess,callBack);
        } else {
            callBack(undefined);
        }
    },
    selectById(processId,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/process/get?processId=" + processId;
            http.get(url,callBack);
        }else {
            callBack(undefined);
        }
    },
    export(TestProcess,page=1,limit=10,callBack){
        let token = localStorage.getItem("token");
        if (token){
            let url = config.defectBaseUrl + "/process/export?page=" + page + "&limit=" + limit;
            http.get(url,callBack);
        }else {
            callBack(undefined);
        }
    },







}

export default TestProcessRequest